<template>
    <elm-page-tb>
        <template #top>
          <el-input placeholder="请查询输入内容" prefix-icon='el-icon-search' size="mini" style="width: 250px;" v-model="postData.name" clearable></el-input>
            <right>
                <el-button-group>
                  <el-button icon="el-icon-search" size="mini" @click="tablebinding()">查询</el-button>
                    <elm-open-button url="plan_edit" icon="el-icon-edit" title="新增" width="800" height="40%" :data="{pid: '0'}">新增</elm-open-button>
                </el-button-group>
            </right>
        </template>
        <elm-table url="/business/plm/plan/GetData" :post-data="postData" :page-size="50" height="100%">
          <el-table-column prop="sys_code_key" label="计划编号" align="center" width="120"></el-table-column>
          <el-table-column prop="name" label="计划名称" header-align="center"></el-table-column>
          <el-table-column prop="create_date" :formatter="formatDate" label="创建时间" align="center" width="100"></el-table-column>
          <el-table-column prop="remark" label="备注" align="center"></el-table-column>
          <el-table-column fixed="right" label="查看" width="80px" align="center">
            <template v-slot="scope">
              <elm-open-button url="plan_task_show" title="查看详情" width="80%" height="80%"
                               :data="{ plan_code:scope.row.sys_code_key }" type="text">查看详情</elm-open-button>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="工作" width="80px" align="center">
            <template v-slot="scope">
              <elm-open-button url="plan_task" title="工作配置" width="80%" height="80%"
                               :data="{ plan_code:scope.row.sys_code_key }" type="text">工作配置</elm-open-button>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100px" align="center">
            <template v-slot="scope">
              <elm-open-button url="plan_edit" :title="'编辑[' + scope.row.name + ']'" width="800" height="40%" :data="{ model: scope.row }" type="text">编辑</elm-open-button>
              <el-button type="text" size="mini" @click="deleteData(scope.row)">删除</el-button>
            </template>
          </el-table-column>
      </elm-table>
    </elm-page-tb>
</template>

<script>
export default {
    extends: elmVueBase,
    data() {
        return {
            postData: {name: null },
        }
    },
    async created() {
    },
    methods: {
        async deleteData(data) {
            await this.delete('/business/plm/plan/Delete', { id: data.id });
            let res= await elm.post("/business/plm/plan/task/GetData",{plan_code:data.sys_code_key});
            for(let i=0;i<res.pagedata.length;i++){
              let r=await elm.post("/business/plm/plan/stage/GetData",{plan_id:res.pagedata[i].id});
              if(r.length>0)
                await elm.post("/business/plm/plan/stage/Delete",r[0]);
              await elm.post("/business/plm/plan/task/Delete",res.pagedata[i]);
            }
            this.tablebinding();
        },
    }
}
</script>

<style scoped>
</style>